<?php 

require("../include/config.php");
require("../API/php/fonctions.php");
require("../API/php/header.php");

// phpsql/mysql_getSemaines.php?milis=123456789&ctrl=ok

//[X][0] = lundi_sql
//[X][1] = lundi_fr
//[X][2] = dimanche_sql
//[X][3] = dimanche_fr

// IN obligatoire
$arrayGet = array(
    "ctrl" => null
);

$arrayValeur = recupGet($arrayGet, $bolDecode);

if($arrayValeur["error"] == null){
	// CONNECION SQL
	$db = mysql_connect($host, $base, $mdp)  or die('Erreur de connexion '.mysql_error());

	// CONNECION BASE
	mysql_select_db($base,$db)  or die('Erreur de selection '.mysql_error());
	
//------------------------------------------------------------------
	//pourcent de saisi d activitee
	$sql = "SELECT b.lundi as lundi_sql, DATE_FORMAT(b.lundi,'%d/%m/%Y') as lundi_fr, b.dimanche as dimanche_sql, DATE_FORMAT(b.dimanche,'%d/%m/%Y') as dimanche_fr
FROM (
	SELECT a.L as lundi, DATE_ADD(a.L, INTERVAL +6 DAY) as dimanche
	FROM (
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*0 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*1 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*2 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*3 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*4 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*5 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*6 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*7 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*8 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*9 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*10 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*11 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*12 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*13 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*14 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*15 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*16 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*17 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*18 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*19 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*20 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*21 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*22 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*23 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*24 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*25 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*26 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*27 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*28 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*29 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*30 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*31 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*32 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*33 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*34 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*35 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*36 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*37 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*38 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*39 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*40 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*41 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*42 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*43 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*44 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*45 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*46 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*47 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*48 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*49 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*50 DAY) as L
		UNION ALL
		SELECT DATE_ADD(	DATE_ADD(CURDATE(), INTERVAL (5 + DAYOFWEEK(CURDATE())) * -1 DAY), INTERVAL -7*51 DAY) as L
	) a
) b	
	;";
		
	$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error()); 

	// on fait une boucle qui va faire un tour pour chaque enregistrement 
	while($data = mysql_fetch_assoc($req)) 
	{ 
		$strSorti .= $data['lundi_sql']."&".$data['lundi_fr']."&".$data['dimanche_sql']."&".$data['dimanche_fr']
		."&"
		."\r\n"; 
	}

	// DECONNECION SQL
	mysql_close();
}else{
	$strSorti = "ERROR:".$arrayValeur["error"];
}

require("../API/php/footer.php");
?>